package cn.edu.scau.cmi.tangqingning.controll;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.scau.cmi.tangqingning.dao.impl.UserDaoImpl;
import cn.edu.scau.cmi.tangqingning.model.Student;

/**
 * 控制层-查询学生信息的逻辑处理<br>
* 当客户使用get方式请求Servlet时，Web容器调用doGet方法处理请求，通过调用UserDaoImpl的findStudentById方法查询学生信息
 * @author 庄桂满
 *@see cn.edu.scau.cmi.tangqingning.dao.impl.UserDaoImpl#findStudentById
 */
public class SearchByStudentIdServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException 如果一个错误发生，则抛出此异常
	 * @throws IOException 如果一个错误发生，则抛出此异常
	 */
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * 重写doGet方法
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException 如果一个错误发生，则抛出此异常
	 * @throws IOException 如果一个错误发生，则抛出此异常
	 */
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String stId = request.getParameter("searchId");
		UserDaoImpl userdao = new UserDaoImpl();
		Student student = userdao.findStudentById(stId);
		request.setAttribute("student", student);
		String userMainPage = "showStudent.jsp";
		request.setAttribute("userMainPage", userMainPage);
		RequestDispatcher dispatcher = request.getRequestDispatcher("userMain.jsp");
		dispatcher.forward(request, response);
	}

}
